/* @(#)GSBalanceManageQueryAction.java   
 *
 * Project: GS
 *
 * Modify Information:
 * =============================================================================
 *   Author       Date       Description
 *   ------------ ---------- ---------------------------------------------------
 *   Jenny Li    2006-4-21     新增
 *
 * Copyright Notice:
 * =============================================================================
 *    Copyright (c) 2001-2006 Beijing HiTRUST Technology Co., Ltd. 1808 Room, 
 *        Science & Technology Building, No. 9 South Street, Zhong Guan Cun, 
 *        Haidian District, Beijing ,100081, China All rights reserved.
 *
 *    This software is the confidential and proprietary information of
 *        Beijing HiTRUST Technology Co., Ltd. ("Confidential Information").
 *        You shall not disclose such Confidential Information and shall use it
 *        only in accordance with the terms of the license agreement you entered
 *        into with HiTRUST.
 *
 * Warning:
 * =============================================================================
 * 
 */
package com.hitrust.gs.action;

import java.util.ArrayList;
import java.util.HashMap;

import com.hitrust.gs.bean.GSOperatorBean;
import com.hitrust.gs.bean.GSOrganizationBean;
import com.hitrust.gs.business.GSBalanceProcessor;
import com.hitrust.gs.business.GSOrderDeptInfoProcessor;
import com.hitrust.gs.business.GSOrganizationProcessor;
import com.hitrust.gs.form.GSBalanceManageQueryForm;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.lib.GSLogWriter;
import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.service.GSBaseForm;
import com.hitrust.gs.util.exception.GSException;
import com.hitrust.gs.util.page.ResultProcess;
import com.hitrust.gs.vo.GSBalanceManageQueryVO;

/**
 * 
 */
public class GSBalanceManageQueryAction extends GSBaseAction {


    public String execute(GSBaseForm aForm) throws Exception {
        
        GSBalanceManageQueryForm tForm = (GSBalanceManageQueryForm)aForm;
        try{
            //取得页面参数组装成查询VO对象
            GSBalanceManageQueryVO tVO = new GSBalanceManageQueryVO();
            tVO.orderDeptId = tForm.getOrderDeptId();
            tVO.status = tForm.getStatus();
            tVO.deptCategory = tForm.getBalanceType();
            tVO.payType = tForm.getPayType();
            String year = tForm.getBalanceYear();
            String month = tForm.getBalanceMonth();
            tVO.provider = tForm.getProvider();
            if(Integer.parseInt(month) < 10){
                month = "0" + month;
            }
            tVO.balanceYM = year + month;
            
            //取得当前操作员可查询的订货单位
            GSOperatorBean tOperBean = (GSOperatorBean)aForm.getSession().getAttribute(GSBaseConstants.LOGIN);
            GSOrganizationProcessor orgpro=new GSOrganizationProcessor();
            ArrayList arr=orgpro.getOrgSub(tOperBean.getGs_oper_org_id());
            ArrayList ary=new ArrayList();
            for (int i = 0; i < arr.size(); i++) {
                String[] tOrderDept = new String[2];
                GSOrganizationBean ob=(GSOrganizationBean) arr.get(i);
                tOrderDept[0]=ob.getGs_org_id();
                tOrderDept[1]=ob.getGs_org_name();
                ary.add(tOrderDept);
            }
            aForm.getRequest().setAttribute("shiporg", ary);
            //查询对帐信息
            GSBalanceProcessor tProc = new GSBalanceProcessor();
            ArrayList tList =new ArrayList();
            if(tVO.payType.equals("1")){
                tList=tProc.getBalanceInfo3(tVO,ary);
            }else{
                tList=tProc.getBalanceInfo4(tVO);
            }
            ResultProcess tRs = new ResultProcess();
            tRs.setResult(tList);
            tForm.getRequest().setAttribute("balancemsg",tRs);
        }catch(Exception e){
            if(e instanceof GSException){
            }else{
                GSLogWriter.error(this,e.toString());
            }
            tForm.getRequest().setAttribute("action","A180201.do");                
            throw e;
        }
        return GSBaseConstants.FORWARD_SUCCESS;
    }

}
